package com.taptech.doufu.net.httputils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;

import com.taptech.doufu.app.WeMediaApplication;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.util.DateUtil;
import com.taptech.doufu.util.ScreenUtil;

import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;

import java.io.Serializable;

public class DiaobaoCookieStore extends BasicCookieStore implements
		Serializable {
	private static final long serialVersionUID = 1L;
	public static final String AID = "aid";
	public static final String AV = "av";
	public static final String CH = "ch";
	public static final String OS = "os";
	public static final String MD = "md";
	public static final String host = Constant.HOST_END_PAST;
	public static final String SCREEN_WIDTH_HEIGHT = "wh";
	public static final String SEXUALITY = "xx";

	public DiaobaoCookieStore() {
		Context context = WeMediaApplication.applicationContext;
		
		PackageInfo packInfo;
		try {
			packInfo = context.getPackageManager().getPackageInfo(
					context.getPackageName(), 0);
			String version = packInfo.versionName;

			ApplicationInfo appInfo = context.getPackageManager()
					.getApplicationInfo(context.getPackageName(),
							PackageManager.GET_META_DATA);
			String channel = appInfo.metaData.getString("UMENG_CHANNEL");
			BasicClientCookie cookie = new BasicClientCookie(AID, Constant.APPAID);
			cookie.setDomain(host);
			cookie.setPath("/");
			cookie.setExpiryDate(DateUtil.strToDate("2034-12-31"));
			addCookie(cookie);
			cookie = new BasicClientCookie(AV, version);
			cookie.setDomain(host);
			cookie.setPath("/");
			cookie.setExpiryDate(DateUtil.strToDate("2034-12-31"));
			addCookie(cookie);
			cookie = new BasicClientCookie(CH, channel);
			cookie.setDomain(host);
			cookie.setPath("/");
			cookie.setExpiryDate(DateUtil.strToDate("2034-12-31"));
			addCookie(cookie);
			cookie = new BasicClientCookie(OS, "Android-"
					+ Build.VERSION.RELEASE);
			cookie.setDomain(host);
			cookie.setPath("/");
			cookie.setExpiryDate(DateUtil.strToDate("2034-12-31"));
			addCookie(cookie);
			cookie = new BasicClientCookie(MD, Build.MODEL);
			cookie.setDomain(host);
			cookie.setPath("/");
			cookie.setExpiryDate(DateUtil.strToDate("2034-12-31"));
			addCookie(cookie);
			cookie = new BasicClientCookie(SCREEN_WIDTH_HEIGHT , ScreenUtil.getScreenWidth(context) + "*" + ScreenUtil.getScreenHeight(context));
			cookie.setDomain(host);
			cookie.setPath("/");
			cookie.setExpiryDate(DateUtil.strToDate("2034-12-31"));
			addCookie(cookie);
			//添加tag的cookie
			cookie = new BasicClientCookie(SEXUALITY , ((WeMediaApplication)(WeMediaApplication.applicationContext)).sexType);
//			cookie.setDomain(host);
//			cookie.setPath("/");
//			cookie.setExpiryDate(DateUtil.strToDate("2034-12-31"));
//			addCookie(cookie);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}

	}

}
